#!/bin/sh

usage()
{
    echo "Usage :"
    echo "catVectormap.sh <output basename> <input1 basename> <input2 basename>"
    exit 1
}

wrong()
{
        echo "Something went wrong:"
        if [ "x$1" != "x" ]; then
                echo "$1"
        fi
        exit 1
}

n=$#

if [ "x${n}" != "x3" ]; then
    usage
fi

outbase=$1
inbase1=$2
inbase2=$3


if [ ! -e "${inbase1}.mhd" ]; then
	wrong "${inbase1} mhd file does not exist"
fi

if [ ! -e "${inbase1}.raw" ]; then
	wrong "${inbase1} raw file does not exist"
fi

if [ ! -e "${inbase2}.mhd" ]; then
	wrong "${inbase2} mhd file does not exist"
fi

if [ ! -e "${inbase2}.raw" ]; then
	wrong "${inbase2} raw file does not exist"
fi

cp -p "${inbase1}.mhd" "${outbase}.mhd"
catVectormap "${outbase}" "${inbase1}" "${inbase2}"
